﻿using System;
using System.Linq;

namespace WebChat
{
    public partial class Chat : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void ButtonSend_Click(object sender, EventArgs e)
        {
            ChatDBEntities dbContext = new ChatDBEntities();
            using (dbContext)
            {
                Message message = new Message() { Body = TextBoxMessageToPost.Text };
                TextBoxMessageToPost.Text = null;
                dbContext.Messages.AddObject(message);
                dbContext.SaveChanges();
                ListviewMessages.DataBind();
                TextBoxMessageToPost.Focus();
            }
        }

        protected void TimerRefreshChat_Tick(object sender, EventArgs e)
        {
            ListviewMessages.DataBind();
        }
    }
}